//https://leetcode.cn/problems/subtree-of-another-tree/description/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

bool isSametree(struct TreeNode* root, struct TreeNode* subRoot)
{
    //都为空
    if (root == NULL && subRoot == NULL)
    {
        return true;
    }

    //只有一个为空
    if (root == NULL || subRoot == NULL)
    {
        return false;
    }

    //都不为空
    if (root->val != subRoot->val)
    {
        return false;
    }

    return isSametree(root->left, subRoot->left) && isSametree(root->right, subRoot->right);
}

bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if (root == NULL)
    {
        return false;
    }

    if (isSametree(root, subRoot))
    {
        return true;
    }

    //root的左右子树分别与subRoot比较
    return isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);

}